package com.hy.controller;

import com.hy.bean.*;
import com.hy.dto.CarDto;
import com.hy.service.CarpartstableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (Carpartstable)表控制层
 *
 * @author makejava
 * @since 2024-05-14 22:03:32
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("carpartstable")
public class CarpartstableController {
    /**
     * 服务对象
     */
    @Resource
    private CarpartstableService carpartstableService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/listLimit")
    public RespBean queryByPage(Integer limit, Integer page) {
        return carpartstableService.queryAllByLimit(limit, page);
    }

    @GetMapping("/list")
    public PageResult queryByPage02(@RequestParam(defaultValue = "1") Integer currPage, @RequestParam(defaultValue = "5") Integer pageSize, CarDto carDto) {
        return carpartstableService.queryAll(currPage, pageSize, carDto);
    }

    /**
     * 根据条件查询
     *
     * @return 查询结果
     */
    @GetMapping("/queryAll")
    public RespBean queryAll() {
        List<Carpartstable>  carpartstables = carpartstableService.select();
        return RespBean.success("OK",carpartstables);
    }

    @GetMapping("/queryList")
    public RespBean queryList(String partCode, String[] timeHorizon, String creator) {
        List<Carpartstable>  carpartstables = null ;
        if (timeHorizon==null || timeHorizon.length ==0) {
            carpartstables =  carpartstableService.select(partCode,null,null,creator);
        }else{
            carpartstables =  carpartstableService.select(partCode,timeHorizon[0],timeHorizon[1],creator);
        }
        return RespBean.success("OK",carpartstables);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getById/{id}")
    public Carpartstable queryById(@PathVariable("id") Integer id) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param carpartstable 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public RespBean add(Carpartstable carpartstable) {
        log.debug("Request to save Carpartstable : {}", carpartstable);
        return null;
    }

    /**
     * 编辑数据
     *
     * @param carpartstable 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public RespBean edit(Carpartstable carpartstable) {
        return null;
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteByid/{id}")
    public RespBean deleteById(@PathVariable("id") Integer id) {
        return null;
    }

    @PostMapping("/addCar")
    public RespBean addCar(@RequestBody Carpartstable carpartstable){
        log.debug("Request to save Carpartstable :=====> {}", carpartstable);
        carpartstable.setPartcreatedate(new Date());
        return carpartstableService.save(carpartstable);
    }
}

